package com.zhanglu.fun.services.datacenter.forumpost;

import com.zhanglu.fun.services.datacenter.entity.ForumPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhanglu.fun.services.datacenter.common.ResultResponse;

import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhanglu
 */
@RestController
@Slf4j
public class ForumPostRouter {
    @Autowired
    private ForumPostService forumPostService;

    @ApiOperation(value = "查询帖子信息", notes = "根据thread表主键id查询帖子信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "threadId", value = "thread表主键id", required = true, dataType = "Long", paramType = "path")})
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class)})
    @GetMapping("forum/posts/{threadId}")
    public ResultResponse getForumPostsByThreadId(@PathVariable(value = "threadId", required = false) Long threadId) {
        log.info("getForumPostsByThreadId receive param:[threadId is:{}]", threadId);
        return forumPostService.getForumPostsByThreadId(threadId);
    }

    @ApiOperation(value = "回复帖子", notes = "回复帖子")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class)})
    @PutMapping("forum/post")
    public ResultResponse addForumPost(ForumPost post) {
        return forumPostService.addForumPost(post);
    }

}
